use([
            "public/javascripts/service/user_securityService.js",
            "public/javascripts/widget/slider/slider.js",
            "public/javascripts/widget/prompt/prompt.js",
            "public/common/des.js"
        ], function (user_securityService, SliderComponent, PromptComponent, Des) {
            var PageComponent = React.createClass({
                componentDidMount: function () {

                },
                receiveMsg: function (data) {

                },
                getInitialState: function () {
                    return {
                        originPwd: '',
                        originPwdTipTxt: '6-18位，大小写字母、数字、符号至少三种',
                        newPwd: '',
                        newPwdTipTxt: '6-18位，大小写字母、数字、符号至少三种',
                        repeatPwd: '',
                        strongTips: false,
                        weak: false,
                        medium: false,
                        strong: false,
                    };
                },
                validateOrigin: function (e) {
                    var value = e.target.value;
                    this.setState({
                        originPwd: value
                    })
                    if (value.length < 6) {
                        this.setState({
                            originPwdTip: true,
                            originPwdTipTxt: '6-18位，大小写字母、数字、符号至少三种',
                        })
                    } else if (value === this.state.newPwd) {
                        this.setState({
                            originPwdTip: true,
                            originPwdTipTxt: '新密码不能与旧密码相同',
                        })
                    } else {
                        this.setState({
                            originPwdTip: false
                        })
                    }
                },
                validateRepeat: function (e) {
                    var value = e.target.value;
                    this.setState({
                        repeatPwd: value
                    })
                    if (value.length < 6 || value !== this.state.newPwd) {
                        this.setState({
                            repeatPwdTip: true
                        })
                    } else {
                        this.setState({
                            repeatPwdTip: false
                        })
                    }
                },
                checkPwdStrength: function (e) {
                    var value = e.target.value;
                    this.setState({
                        newPwd: value
                    })
                    if (value === this.state.originPwd) {
                        this.setState({
                            newPwdTip: true,
                            strongTips: false,
                            newPwdTipTxt: '新密码不能与旧密码相同'
                        })
                    } else {
                        //正则表达式验证符合要求的
                        if (value.length >= 6) {
                            var modes = 0;
                            if (/\d/.test(value)) modes++; //数字
                            if (/[a-z]/.test(value)) modes++; //小写
                            if (/[A-Z]/.test(value)) modes++; //大写  
                            if (/((?=[\x21-\x7e]+)[^A-Za-z0-9])/.test(value)) modes++; //特殊字符
                            switch (modes) {
                                case 2:
                                    this.setState({
                                        strongTips: true,
                                        weak: true,
                                        medium: false,
                                        strong: false,
                                        newPwdTip: false,
                                    });
                                    break;
                                case 3:
                                    this.setState({
                                        strongTips: true,
                                        weak: false,
                                        medium: true,
                                        strong: false,
                                        newPwdTip: false,
                                    });
                                    break;
                                case 4:
                                    this.setState({
                                        strongTips: true,
                                        weak: false,
                                        medium: true,
                                        strong: true,
                                        newPwdTip: false,
                                    });
                                    break;
                                default:
                                    this.setState({
                                        strongTips: false,
                                        weak: false,
                                        medium: false,
                                        strong: false,
                                        newPwdTip: true,
                                        newPwdTipTxt: '6-18位，大小写字母、数字、符号至少三种',
                                    });
                                    break;
                            }
                        } else {
                            this.setState({
                                strongTips: false,
                                weak: false,
                                medium: false,
                                strong: false,
                                newPwdTip: true,
                                newPwdTipTxt: '6-18位，大小写字母、数字、符号至少三种',
                            })
                        }
                    }
                },
                confirmChangePwd: function (e) {
                    if (!this.state.originPwd) {
                        this.setState({
                            originPwdTip: true
                        })
                        return;
                    }
                    if (!this.state.newPwd) {
                        this.setState({
                            newPwdTip: true
                        })
                        return;
                    }
                    if (this.state.newPwd === this.state.originPwd) {
                        this.setState({
                            newPwdTip: true,
                            strongTips: false,
                            newPwdTipTxt: '新密码不能与旧密码相同',
                        })
                        return;
                    }
                    if (this.state.weak) {
                        console.log(1);
                        this.setState({
                            newPwdTip: true,
                            strongTips: false,
                            newPwdTipTxt: '密码强度过低，请重新输入',
                        })
                        return;
                    }
                    if (this.state.originPwdTip || this.state.newPwdTip) {
                        return;
                    }
                    if (!this.state.repeatPwd) {
                        this.setState({
                            repeatPwdTip: true
                        })
                        return;
                    }
                    if (this.state.repeatPwd !== this.state.newPwd) {
                        this.setState({
                            repeatPwdTip: true
                        })
                        return;
                    }

                    var params = {
                        oldPassword: Des.enc(this.state.originPwd),
                        newPassword: Des.enc(this.state.newPwd),
                        repeateNewPassword: Des.enc(this.state.repeatPwd)
                    };
                    var _this = this;
                    user_securityService.changePassword(params, function (res) {
                        if (res.errorCode === 0) {
                            PromptComponent.init({
                                type: 'success',
                                msg: '更新密码成功，请稍后重新登录'
                            }).show();
                            $.ajax({
                                url:"/api/v1/auth/logout",
                                success:function(res){
                                    cookie.delete('token');
                                    cookie.delete('username');
                                    window.location.href = '/';
                                }
                            });
                        } else {
                            PromptComponent.init({
                                type: 'warning',
                                msg: res.msg
                            }).show()
                        }
                    })
                },
                render: function () {
                    var data = this.state.data;
                    return ~init;
                }
            });
            if (typeof ReactDOM != "undefined") {
                ReactDOM.render( < PageComponent data = {
                        storage
                    }
                    />, document.getElementById('container'));
                }
                module.exports = PageComponent;
            });